package com.clkj.aimin.controller;

import com.clkj.aimin.pojo.common.Result;
import com.clkj.aimin.pojo.common.StatusCode;
import com.clkj.aimin.pojo.doctor.Doctor;
import com.clkj.aimin.pojo.helper.HelperTalk;
import com.clkj.aimin.pojo.user.User;
import com.clkj.aimin.pojo.user.UserOrder;
import com.clkj.aimin.service.helper.HelperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/helper")
@CrossOrigin
@Api(value = "/helper", tags = {"医生助理api"})
public class HelperController {

    @Autowired
    private HelperService helperService;

    @ApiOperation(value = "客服获取我的患者")
    @PostMapping("/getPatientList")
    public Result getPatientList(Integer userId) {
        try {
            List<User> list =  helperService.getPatientList(userId);
            return new Result(true, StatusCode.OK, "获取成功", list);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "获取失败", null);
        }
    }
    @ApiOperation(value = "聊天:客服获取我和患者的聊天列表")
    @PostMapping("/getHelperTalkInfo")
    public Result getHelperTalkInfo(Integer helperId) {
        try {
            List<HelperTalk> list =  helperService.getHelperTalkInfo(helperId);
            return new Result(true, StatusCode.OK, "获取成功", list);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "获取失败", null);
        }
    }
    @ApiOperation(value = "聊天:客服根据parentId获取聊天记录")
    @PostMapping("/getHelperTalk")
    public Result getHelperTalk(Integer parentId) {
        try {
            List<HelperTalk> list =  helperService.getHelperTalk(parentId);
            return new Result(true, StatusCode.OK, "获取成功", list);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "获取失败", null);
        }
    }

    @ApiOperation(value = "聊天:客服根据聊天id添加聊天")
    @PostMapping("/addHelperTalk")
    public Result addHelperTalk(Integer talkId,Integer userId, Integer helpId, String content) {
        try {
            helperService.addHelperTalk(talkId,userId,helpId,content);
            return new Result(true, StatusCode.OK, "添加成功", null);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "添加失败", null);
        }
    }

    @ApiOperation(value = "根据客服id获取客服基本信息")
    @PostMapping("/getHelperInfo")
    public Result getHelperInfo(Integer helperId) {
        try {
            User user =  helperService.getHelperInfo(helperId);
            return new Result(true, StatusCode.OK, "获取成功", user);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "获取失败", null);
        }
    }
    @ApiOperation(value = "app---医助获取加号、亲情服务申请列表")
    @PostMapping("/getOrderList")
    public Result getOrderList(Integer userId,@ApiParam(value = "0全部，1是待审核",name="flag")@RequestParam("flag") Integer flag) {
        try {
            List<UserOrder> list =  helperService.getOrderList(userId,flag);
            return new Result(true, StatusCode.OK, "获取成功", list);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "获取失败", null);
        }
    }
    @ApiOperation(value = "app--医助核销加号亲情服务申请")
    @PostMapping("/updateOrderStatus")
    public Result updateOrderStatus(Integer orderId,@ApiParam(value = "0审核不通过，1审核通过",name="status")@RequestParam("status") Integer status,
                                    @ApiParam(value = "实际就诊时间",name="dateTime")@RequestParam("dateTime")String dateTime,
                                    @ApiParam(value = "驳回原因",name="note")@RequestParam("note")String note) {
        try {
            helperService.updateOrderStatus(orderId,status,dateTime,note);
            return new Result(true, StatusCode.OK, "更新成功", null);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "更新失败", null);
        }
    }
    @ApiOperation(value = "app--根据用户id获取患者详情")
    @PostMapping("/getPatientInfo")
    public Result getPatientInfo(Integer userId) {
        try {
            Map Map =  helperService.getPatientInfo(userId);
            return new Result(true, StatusCode.OK, "获取成功", Map);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "获取失败", null);
        }
    }


}
